<style>
    .control-group .form-group{
       margin-bottom:0!important;
    }
</style>
<?php

use doumiaoduo\layer\LayerConfirmWidget;
use doumiaoduo\layer\LayerIframeWidget;
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;
use yii\widgets\ActiveForm;

use doumiaoduo\layer\LayerAsset;

LayerAsset::register($this);

LayerConfirmWidget::widget();
LayerIframeWidget::widget();
?>
    <div class="yx-cnt-box yx-praise-content yx-radius2">
        <div class="yx-praise-box">
            <div class="yx-search-class">
                <a href="<?=Fun::url(['cus/customer/studentdetails','id'=>\Yii::$app->request->get('id')])?>">
                    <button type="button" class="btn yx-back-list yx-radius5 yx-width110">返回上级</button>
                </a>
                <div class="yx-bgf7 yx-height108" style="margin: 0 10px">
                    <h4 class="yx-teacher-praise yx-floatl ">会员姓名：<?=$modelCustomer->name?></h4>
                    <h4 class="yx-teacher-praise yx-floatl ">学员姓名：<?=$student->name?></h4>
                    <h4 class="yx-teacher-praise yx-pl20 yx-floatl">当前可用奖学金：<span class="yx-color2cb4f3 yx-font16">0</span>元</h4>
                    <h4 class="yx-teacher-praise yx-pl20 yx-floatl">当前可用余额：<span class="yx-color2cb4f3 yx-font16"><?=$modelCustomer->account?></span>元</h4>
                    <div class="yx-clear"></div>
                </div>
                <div class="yx-class-box yx-pt18 yx-pb0">
                    <div>
                        <?= (new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer', 'course', false, ['rel' => 'dialog-show-iframe', 'class' => 'btn yx-batch-settlement yx-radius2', 'data' => ['id' => \Yii::$app->request->get('id'), 'name' => '选择课程','btn1'=>'添加']],'cus'); ?>
                    </div>
                    <div class="docs-main">
                        <table id="tablep" class="tablesaw table yx-table1 yx-table3 yx-table5 table-striped with-check" data-url="<?=Fun::url('cus/customer/goodsprice')?>">
                            <thead>
                                <tr class="yx-bgd2f6ec">
                                    <th>商品名称</th>
                                    <th>商品类型</th>
                                    <th>库存总量</th>
                                    <th>课次价格</th>
                                    <th>教师名称</th>
                                    <th>教室</th>
                                    <th>上课时间</th>
                                    <th>满额人数</th>
                                </tr>
                            </thead>
                        </table>
                        <div class="price_list">
                            <div style="float: left; width: 450px">
                                <span class="zx-label" style="width: auto !important">选择价格套餐:</span>
                                <select id="goods_price_id" class="form-control" name="goods_price_id" style="width:320px" data-thishidden="selectgoodsprice" data-otherhidden="selectartprice" data-act="orders-goods_price_id">
                                    <option value="">请选择...</option>
                                </select>
                                <input type="hidden" id="selectgoodsprice" name="goods_hidden" value="0">
                            </div>
                            <div class="yx-clear"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="yx-class-box" style="padding-top: 10px">
                <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false,'options'=>['class'=>'form-validate form-horizontal']]); ?>
                <div class="control-group" style="display: none;margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['total_amount']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'total_amount', ['template' => '{input}{error}'])->hiddenInput(); ?>
                    </div>
                </div>
                <div class="control-group" style="display: none;margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['final_amount']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'final_amount', ['template' => '{input}{error}'])->hiddenInput(); ?>
                    </div>
                </div>
                <div class="control-group" style="margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime">合计金额</label>
                    <div class="controls">
                        <span class="yx-font18 yx-color4f4f4f" style="line-height:30px;" id="amount">0.00</span>
                    </div>
                </div>

                <div class="control-group" style="margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['discount_amount']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'discount_amount', ['template' => '{input}{error}'])->textInput(['style' => 'width:220px', 'class' => 'input-text','readonly'=>true]); ?>
                    </div>
                </div>
                <div class="control-group" style="margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['goods_id']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'goods_id', ['template' => '{input}{error}'])->textInput(['style' => 'width:220px', 'class' => 'input-text','readonly'=>true]); ?>
                    </div>
                </div>
                <div class="control-group"  style="display: none;margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['goods_price_id']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'goods_price_id', ['template' => '{input}{error}'])->textInput(['style' => 'width:220px', 'class' => 'input-text','readonly'=>true]); ?>
                    </div>
                </div>
                <div class="control-group" style="margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['remarks']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'remarks', ['template' => '{input}{error}{hint}'])->textarea(['rows' => 2, 'class' => 'textarea_editor yx-width510 yx-height56']) ?>
                    </div>
                </div>
                <div class="yx-button-group">
                    <button type="button" id="dosubmit" class="btn yx-save yx-radius50">提交</button>
                    <a href="" class="btn yx-close1 yx-radius50 yx-ml4" style="display: inline-block">返回</a>
                </div>
                <?php ActiveForm::end(); ?>
            </div>
        </div>
    </div>
<?php
$js=<<<JS
    $(document).on('click','#dosubmit',function() {
      var goods_price_id = $('select[name="goods_price_id"]').val();
      if(goods_price_id.length == 0){
          layer.msg("请选择先添加商品并选择价格！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 2000});
          return false;
      }else{
          $('#goods_price_id').val('');
          $('#w0').submit();
      }
 });
  $(document).on('click','.layui-layer-btn0',function(e){
         //e.preventDefault();
         var price =0;
         var input = $("iframe[id^=layui-layer-iframe]").contents().find('input[name="checkbox"]:checked');
         var tr = input.parents('tr');
         var id = input.val();
         var str = '';
         var url = $('#tablep').data('url');
         if(typeof(id) === 'undefined'){
           layer.msg("请先选择商品！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
           return false;
         }else{
            
            $.ajax({
             url:url,
             type:'post',
             data:{id:id,ajax:'goodsprice',_csrf:yii.getCsrfToken()},
             dataType:'json',
             beforeSend:function(){
                layer.load(0, { shade: [0.5, '#393D49'] });
             },
             complete:function(){
              layer.close(layer.load(0, { shade: [0.5, '#393D49'] }));  
            },
            success:function(data){
               if(data.status == 1){
                   var str = '<option value="">请选择...</option>';
                   var pricelist = data.priceList;
                   for(var i= 0 ;i<pricelist.length;i++){
                       var item = pricelist[i];
                       str += '<option value="'+item.id+'" data-price="'+item.lesson_price+'">'+item.price_name+item.activity_name+'-'+item.lesson+'节课-'+item.lesson_price+'元-'+item.scholarship_desc+'</option>';
                   }
                   $('#goods_price_id').html(str);
               }
            }
         });
              tr.find('td').eq(0).remove();
              str += '<tr>';
              str += tr.html();
              str += '</tr>';
              $('tbody').html('');             
             $('#orders-goods_id').val(id);
             $('.tablesaw').append(str);       
             $(".layui-layer-btn1").click();
         }
   });


JS;
\Yii::$app->view->registerJs($js);
?>
